package controller;

import com.github.pagehelper.PageInfo;
import entity.Customer_loss;
import entity.LayRequest;
import entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.Customer_lossService;

import java.util.List;

@Controller
@RequestMapping("/customer")
public class Customer_lossController {
    @Autowired
    private Customer_lossService customer_lossService;

    @RequestMapping("/tolossAdd")
    public String toAdd(){
        return "lossadd.jsp";
    }
    @ResponseBody
    @RequestMapping("/lossadd")
    public MyResult add(Customer_loss customer_loss){
        boolean flag = customer_lossService.insert(customer_loss);
        return new MyResult(0);
    }

    @RequestMapping("/tolossUpdate")
    public String toUpdate(Integer id,ModelMap modelMap){
        Customer_loss customer_loss = customer_lossService.selectById(id);
        modelMap.addAttribute("customer_loss",customer_loss);
        return "lossupdate.jsp";
    }
    @ResponseBody
    @RequestMapping("/lossupdate")
    public MyResult update(Customer_loss customer_loss){
        boolean flag = customer_lossService.update(customer_loss);
        return new MyResult(0);
    }

    @ResponseBody
    @RequestMapping("/lossdelete")
    public MyResult delete(Integer id){
        boolean flag = customer_lossService.delete(id);
        return new MyResult(0);
    }

    @ResponseBody
    @RequestMapping("/losslist")
    public MyResult<List<Customer_loss>> losslist(LayRequest layRequest,ModelMap modelMap){
        PageInfo<Customer_loss> customer_lossPageInfo = customer_lossService.selectByPage(layRequest);
        modelMap.addAttribute("customer_lossPageInfo",customer_lossPageInfo);
        return new MyResult<>(0,customer_lossPageInfo.getTotal(),customer_lossPageInfo.getList());
    }
}
